﻿/* 
 * Copyright (c) 2011-12-12 Andrey Bulygin
 * 
 * This file is part of Interceptor.
 * Interceptor is free software: you can redistribute it and/or modify it under the terms of the GNU 
 * Library General Public License as published by the Free Software Foundation, either version 3 of the 
 * License, or (at your option) any later version.
 * 
 * Interceptor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 
 * the GNU Library General Public License for more details. You should have received a copy of the GNU 
 * Library General Public License along with Interceptor. If not, write to the Free Software Foundation, Inc., 59 
 * Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 */

using System;

namespace Interceptor.Core
{
	internal struct Pair<T1, T2> : IEquatable<Pair<T1, T2>>
	{
		public Pair(T1 value1, T2 value2)
		{
			if (value1 == null)
				throw new ArgumentNullException("value1");
			if (value2 == null)
				throw new ArgumentNullException("value2");

			_value1 = value1;
			_value2 = value2;
		}

		private T1 _value1;
		private T2 _value2;
		public T1 Value1 { get { return _value1; } }
		public T2 Value2 { get { return _value2; } }

		public override bool Equals(object obj)
		{
			if (!(obj is Pair<T1, T2>))
				return false;
			
			return Equals((Pair<T1, T2>)obj);
		}
		public override int GetHashCode()
		{
			var hash = 23;
			hash = hash * 37 + Value1.GetHashCode();
			hash = hash * 37 + Value2.GetHashCode();
			return hash;
		}
		public bool Equals(Pair<T1, T2> other)
		{
			return Value1.Equals(other.Value1) &&
					Value2.Equals(other.Value2);
		}
	}
}
